<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/9/10
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>公告管理首页</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/notice.css">
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-3.1.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery.validate.js"></script>
    <link rel="stylesheet" href="/static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/static/frame/static/css/style.css">
    <link rel="icon" href="/static/frame/static/image/code.png">
</head>
<style>
    .showmessages{
        position: absolute;
        width: 100%;
        margin-top: 25px;
    }
</style>
<body>
        <div class="titleall">
            <div class="titleph">
                <img src="${pageContext.request.contextPath}/static/images/gonggao.png" style="width:100%;height:100%;"/>
            </div>
            <div class="titleword">公告管理 >>> 公告列表</div>
        </div>
    <div class="rolephall1">
        <img src="${pageContext.request.contextPath}/static/images/gonggaofind.png" style="width:100%;height:100%"/>
    </div>
        <form action="selectnoticeName" method="post" id="myform">
            <input type="text" class="selectbox" name="noticeName" id="noticeId" placeholder="发布人姓名 / Name"/>
            <input type="submit" value="查询" class="selectbutton"/>
        </form>
        <div class="contentall">
            <%--<div class="powerword">公告信息</div>--%>
            <%--<div class="roleph1">--%>
                <%--<img src="${pageContext.request.contextPath}/static/images/userinfo.png" style="width:100%;height:100%"/>--%>
            <%--</div>--%>
            <div id="tableall" class="showmessages">
                <table class="layui-table">
                    <thead>
                    <tr >
                        <th style="border:1px solid #999;text-align: center;color:#EC9D1A;font-weight:600;">序号</th>
                        <th style="border:1px solid #999;text-align: center;color:#EC9D1A;font-weight:600;">公告内容</th>
                        <th style="border:1px solid #999;text-align: center;color:#EC9D1A;font-weight:600;">发布人姓名</th>
                        <th style="border:1px solid #999;text-align: center;color:#EC9D1A;font-weight:600;">公告创建时间</th>
                        <th style="border:1px solid #999;text-align: center;color:#EC9D1A;font-weight:600;">删除公告</th>
                    </tr>
                    </thead>
                    <tbody id="clear" style="display: none">
                    <script>var arr1=[]</script>
                    <c:forEach items="${sessionScope.noticelist}" var="notice" varStatus="sta">
                        <tr id="noticeorder${sta.count}" class="rolerow1">
                            <td style="border:1px solid #999;color:#777;font-weight:600">${sta.count}</td>
                            <td style="border:1px solid #999"><textarea  disabled="disabled" readonly="readonly" style=" resize:none;width:100%;height:300px;border: 1px solid darkgreen;">${notice.notice_content}</textarea></td>
                            <td style="border:1px solid #999">${noticeNames[sta.count-1]}</td>
                            <td class="createtime" style="border:1px solid #999">${notice.notice_createtime}</td>
                            <form method="post">
                                <td style="border:1px solid #999">
                                    <input type="hidden" name="nid" value="${notice.notice_id}" class="nid"/>
                                    <input type="button" value="删除" class="deleterole" onclick="cl(this,${notice.notice_id})" onmouseover="overm(this,${sta.count})"  onmouseout="outm(this,${sta.count})"/>
                                </td>
                            </form>
                        </tr>
                        <script>arr1.push($("#noticeorder${sta.count}")[0])</script>
                    </c:forEach>
                    </tbody>
                    <tbody id="biuuu_city_list"></tbody>
                </table>
                <div id="demo20"></div>
            </div>
        </div>
    <div class="shelter">
        <div class="confirm">
            <div class="tishiph"><img src="${pageContext.request.contextPath}/static/images/tishi.png" style="width:100%;height:100%;"/></div>
            <div class="confirmword">您确定要删除公告吗？</div>
            <div class="close"><img src="${pageContext.request.contextPath}/static/images/close.png" style="width:100%;height:100%;"/></div>
            <input type="button" class="cf" value="确定"/>
        </div>
    </div>
    <div class="shelter1">
        <div class="succ">
            <div class="tishiph1"><img src="${pageContext.request.contextPath}/static/images/cg.png" style="width:100%;height:100%;"/></div>
            <div class="confirmword1">删除公告成功！</div>
            <div class="close1"><img src="${pageContext.request.contextPath}/static/images/close.png" style="width:100%;height:100%;"/></div>
            <input type="button" class="cf1" value="确定"/>
        </div>
    </div>
</body>
<script src="${pageContext.request.contextPath}/static/frame/layui/layui.js" charset="utf-8"></script>
<script>
    var w=$(window).width();
    $(".contentall").innerWidth((w-17)+"px");
    $(".close").click(function(){
        $(".shelter").css("display","none");
    });
    function cl(e,index){
        $(".shelter").css("display","block");
        $(".cf").click(function(){
        $.ajax({
            type:'POST',
            url:"${pageContext.request.contextPath}/deletenotice.do",
            data:{
                nid:index
            },
            dataType:"json",
            success:function(data) {
                if(data==true){
                    $.ajax({
                        type:'POST',
                        url:"${pageContext.request.contextPath}/flushnotice.do",
                        data:"",
                        dataType:"json",
                        success:function(data){
                        }
                    });
                    $(".shelter1").css("display","block");
                    $(".cf1").click(function() {
                        window.location.href="${pageContext.request.contextPath}/notice";
                    });
                    $(".close1").click(function() {
                        window.location.href="${pageContext.request.contextPath}/notice";
                    });
                }
            }
        });
        });
    }
    var noticelist="${sessionScope.noticelist}";
    if(noticelist==""){
        $("#tableall").html("<div class='searchrole'><img src='${pageContext.request.contextPath}/static/images/cry.png'/><div class='noword'>您输入的发布人姓名不存在或者未发布公告！</div></div>");
    }


    /**
     * 时间显示，调整格式
     */
    showtime();
    function showtime() {
        var createtime=$(".createtime");
        createtime.each(function () {
            //调用时间格式转换函数formatDateTime()
            $(this).text(formatDateTime($(this).text()))
        })
    }
    /**
     *
     * 在页面上，转换时间格式
     * @param inputTime
     * @returns {string}
     */
    function formatDateTime(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    };

    function nodeToString ( node ) {
        var tmpNode = document.createElement( "div" );
        tmpNode.appendChild( node.cloneNode( true ) );
        var str = tmpNode.innerHTML;
        tmpNode = node = null; // prevent memory leaks in IE
        return str;
    }
    function clear(){
        document.getElementById('clear').innerHTML=null;
    }

    layui.use(['carousel', 'laypage','laydate','form','upload','jquery'], function(){
        var carousel = layui.carousel
            ,form = layui.form
            ,$=layui.jquery
            ,upload = layui.upload
            ,laypage = layui.laypage
            ,laydate=layui.laydate

        //常规轮播
        carousel.render({
            elem: '#test1'
            ,arrow: 'always'
        });
        var data1= arr1;
        laypage.render({
            elem: 'demo20'
            ,count: data1.length
            ,jump: function(obj){
                //模拟渲染
                document.getElementById('biuuu_city_list').innerHTML = function(){
                    var arr = []
                        ,thisData = data1.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
                    layui.each(thisData, function(index, item){
                        var itemstr=nodeToString(item);
                        arr.push(itemstr);
                    });
                    clear();
                    return arr.join('');
                }();
            }
        });
    });
    $(".selectbox").focus(function(){
        $(".selectbox").css("border","1px solid #333");
    });
    $(".selectbox").focusout(function(){
        $(".selectbox").css("border","1px solid #999");
    });
    function overm(e,index){
        e.style.backgroundColor="rgba(200,0,0,0.8)";
        e.style.color="white";
    }
    function outm(e,index){
        e.style.backgroundColor="rgba(30,120,0,0)";
        e.style.color="#555";
    }
</script>
</html>
